<template>
  <div id="evaluate">
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="80px"
      label-position="top"
    >
      <el-form-item label="贴子类型">
        <el-radio v-model="form.type" label="FIND_HOUSE">找房源</el-radio>
        <el-radio v-model="form.type" label="FIND_ROOMMATE">找室友</el-radio>
        <el-radio v-model="form.type" label="FIND_TENANT">找租客</el-radio>
      </el-form-item>
      <el-form-item label="贴子内容" prop="content">
        <el-input type="textarea" v-model="form.content"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button :plain="true" type="primary" @click="addpost"
          >发布</el-button
        >
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>


<script>
import request from "@/utils/request";
export default {
  name: "HelloWorld",
  data() {
    return {
      //获取localStorage中保存的后台返回的用户信息
      user: localStorage.getItem("user")
        ? JSON.parse(localStorage.getItem("user"))
        : {},
      form: {
        type: "FIND_HOUSE",
        content: "",
      },
      rules: {
        content: [
          { required: true, message: "请输入帖子内容", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    addpost() {
      this.form.userId = this.user.id;
      request.post("/mypost", this.form).then((res) => {
        if (res.code === 200) {
          this.$notify.success("发布成功");
          this.$router.push("/post");
        } else {
          this.$notify.error(res.msg);
        }
      });
    },
  },
};
</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
form.el-form.el-form--label-top {
  margin-top: 100px;
  margin-left: 390px;
  width: 500px;
  border-radius: 8px;
  box-shadow: 5px 4px 14px #bebebe, -20px -20px 60px #ffffff;
  padding: 40px 100px 40px;
}
.el-button--primary {
  margin-left: 150px;
}
</style>